home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Include / d3dx9anim.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-04  |  31.1 KB  |  802 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx9anim.h
  6. //  Content:    D3DX mesh types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9.  
  10. #ifndef __D3DX9ANIM_H__
  11. #define __D3DX9ANIM_H__
  12.  
  13. // {ADE2C06D-3747-4b9f-A514-3440B8284980}
  14. DEFINE_GUID(IID_ID3DXInterpolator, 
  15. 0xade2c06d, 0x3747, 0x4b9f, 0xa5, 0x14, 0x34, 0x40, 0xb8, 0x28, 0x49, 0x80);
  16.  
  17. // {6CAA71F8-0972-4cdb-A55B-43B968997515}
  18. DEFINE_GUID(IID_ID3DXKeyFrameInterpolator, 
  19. 0x6caa71f8, 0x972, 0x4cdb, 0xa5, 0x5b, 0x43, 0xb9, 0x68, 0x99, 0x75, 0x15);
  20.  
  21. // {54B569AC-0AEF-473e-9704-3FEF317F64AB}
  22. DEFINE_GUID(IID_ID3DXAnimationSet, 
  23. 0x54b569ac, 0xaef, 0x473e, 0x97, 0x4, 0x3f, 0xef, 0x31, 0x7f, 0x64, 0xab);
  24.  
  25. // {3A714D34-FF61-421e-909F-639F38356708}
  26. DEFINE_GUID(IID_ID3DXAnimationController, 
  27. 0x3a714d34, 0xff61, 0x421e, 0x90, 0x9f, 0x63, 0x9f, 0x38, 0x35, 0x67, 0x8);
  28.  
  29.  
  30. typedef struct ID3DXInterpolator *LPD3DXINTERPOLATOR;
  31. typedef struct ID3DXKeyFrameInterpolator *LPD3DXKEYFRAMEINTERPOLATOR;
  32. typedef struct ID3DXAnimationSet *LPD3DXANIMATIONSET;
  33. typedef struct ID3DXAnimationController *LPD3DXANIMATIONCONTROLLER;
  34.  
  35. typedef struct ID3DXAllocateHierarchy *LPD3DXALLOCATEHIERARCHY;
  36. typedef struct ID3DXLoadUserData *LPD3DXLOADUSERDATA;
  37. typedef struct ID3DXSaveUserData *LPD3DXSAVEUSERDATA;
  38.  
  39. //----------------------------------------------------------------------------
  40. // This enum defines the type of mesh data present in a MeshData structure
  41. //----------------------------------------------------------------------------
  42. typedef enum _D3DXMESHDATATYPE {
  43.     D3DXMESHTYPE_MESH      = 0x001,     // normal ID3DXMesh data
  44.     D3DXMESHTYPE_PMESH     = 0x002,     // Progressive Mesh - ID3DXPMesh
  45.     D3DXMESHTYPE_PATCHMESH = 0x003,     // Patch MEsh - ID3DXPatchMesh
  46.  
  47.     D3DXMESHTYPE_FORCE_DWORD    = 0x7fffffff, /* force 32-bit size enum */
  48. } D3DXMESHDATATYPE;
  49.  
  50. //----------------------------------------------------------------------------
  51. // This struct encapsulates a the mesh data that can be present in a mesh 
  52. //   container.  The supported mesh types are pMesh, pPMesh, pPatchMesh
  53. //   The valid way to access this is determined by the MeshType enum
  54. //----------------------------------------------------------------------------
  55. typedef struct _D3DXMESHDATA
  56. {
  57.     D3DXMESHDATATYPE Type;
  58.  
  59.     // current mesh data interface
  60.     union
  61.     {
  62.         LPD3DXMESH              pMesh;
  63.         LPD3DXPMESH             pPMesh;
  64.         LPD3DXPATCHMESH         pPatchMesh;
  65.     };
  66.  
  67. } D3DXMESHDATA, *LPD3DXMESHDATA;
  68.  
  69. //----------------------------------------------------------------------------
  70. // This struct encapsulates a mesh object in a transformation frame
  71. // hierarchy. The app can derive from this structure to add other app specific
  72. // data to this
  73. //----------------------------------------------------------------------------
  74. typedef struct _D3DXMESHCONTAINER
  75. {
  76.     LPSTR                   Name;
  77.  
  78.     D3DXMESHDATA            MeshData;
  79.  
  80.     LPD3DXMATERIAL          pMaterials;
  81.     LPD3DXEFFECTINSTANCE    pEffects;
  82.     DWORD                   NumMaterials;
  83.     DWORD                  *pAdjacency;
  84.  
  85.     LPD3DXSKININFO          pSkinInfo;
  86.  
  87.     struct _D3DXMESHCONTAINER *pNextMeshContainer;
  88. } D3DXMESHCONTAINER, *LPD3DXMESHCONTAINER;
  89.  
  90. //----------------------------------------------------------------------------
  91. // This struct is the encapsulates a transform frame in a transformation frame
  92. // hierarchy. The app can derive from this structure to add other app specific
  93. // data to this
  94. //----------------------------------------------------------------------------
  95. typedef struct _D3DXFRAME
  96. {
  97.     LPSTR                   Name;
  98.     D3DXMATRIX              TransformationMatrix;
  99.  
  100.     LPD3DXMESHCONTAINER     pMeshContainer;
  101.  
  102.     struct _D3DXFRAME       *pFrameSibling;
  103.     struct _D3DXFRAME       *pFrameFirstChild;
  104. } D3DXFRAME, *LPD3DXFRAME;
  105.  
  106. #undef INTERFACE
  107. #define INTERFACE ID3DXAllocateHierarchy
  108.  
  109. //----------------------------------------------------------------------------
  110. // This interface is implemented by the application to allocate/free frame and
  111. // mesh container objects. Methods on this are called during loading and
  112. // destroying frame hierarchies
  113. //----------------------------------------------------------------------------
  114. //////////////////////////////////////////////////////////////////////////////
  115. // ID3DXAllocateHierarchy ////////////////////////////////////////////////////
  116. //////////////////////////////////////////////////////////////////////////////
  117. DECLARE_INTERFACE(ID3DXAllocateHierarchy)
  118. {
  119.     // ID3DXAllocateHierarchy
  120.  
  121.     //------------------------------------------------------------------------
  122.     // CreateFrame:
  123.     // ------------
  124.     // Requests allocation of a frame object.
  125.     //
  126.     // Parameters:
  127.     //  Name
  128.     //        Name of the frame to be created
  129.     //    ppNewFrame
  130.     //        Returns returns the created frame object
  131.     //
  132.     //------------------------------------------------------------------------
  133.     STDMETHOD(CreateFrame)(THIS_ LPCSTR Name, 
  134.                             LPD3DXFRAME *ppNewFrame) PURE;
  135.  
  136.     //------------------------------------------------------------------------
  137.     // CreateMeshContainer:
  138.     // --------------------
  139.     // Requests allocation of a mesh container object.
  140.     //
  141.     // Parameters:
  142.     //  Name
  143.     //        Name of the mesh
  144.     //    pMesh
  145.     //        Pointer to the mesh object if basic polygon data found
  146.     //    pPMesh
  147.     //        Pointer to the progressive mesh object if progressive mesh data found
  148.     //    pPatchMesh
  149.     //        Pointer to the patch mesh object if patch data found
  150.     //    pMaterials
  151.     //        Array of materials used in the mesh
  152.     //    pEffectInstances
  153.     //        Array of effect instances used in the mesh
  154.     //    NumMaterials
  155.     //        Num elements in the pMaterials array
  156.     //    pAdjacency
  157.     //        Adjacency array for the mesh
  158.     //    pSkinInfo
  159.     //        Pointer to the skininfo object if the mesh is skinned
  160.     //    pBoneNames
  161.     //        Array of names, one for each bone in the skinned mesh. 
  162.     //        The numberof bones can be found from the pSkinMesh object
  163.     //    pBoneOffsetMatrices
  164.     //        Array of matrices, one for each bone in the skinned mesh.
  165.     //
  166.     //------------------------------------------------------------------------
  167.     STDMETHOD(CreateMeshContainer)(THIS_ LPCSTR Name, LPD3DXMESHDATA pMeshData, 
  168.                             LPD3DXMATERIAL pMaterials, LPD3DXEFFECTINSTANCE pEffectInstances, DWORD NumMaterials, 
  169.                             DWORD *pAdjacency, LPD3DXSKININFO pSkinInfo, 
  170.                             LPD3DXMESHCONTAINER *ppNewMeshContainer) PURE;
  171.  
  172.     //------------------------------------------------------------------------
  173.     // DestroyFrame:
  174.     // -------------
  175.     // Requests de-allocation of a frame object.
  176.     //
  177.     // Parameters:
  178.     //  pFrameToFree
  179.     //        Pointer to the frame to be de-allocated
  180.     //
  181.     //------------------------------------------------------------------------
  182.     STDMETHOD(DestroyFrame)(THIS_ LPD3DXFRAME pFrameToFree) PURE; 
  183.  
  184.     //------------------------------------------------------------------------
  185.     // DestroyMeshContainer:
  186.     // ---------------------
  187.     // Requests de-allocation of a mesh container object.
  188.     //
  189.     // Parameters:
  190.     //  pMeshContainerToFree
  191.     //        Pointer to the mesh container object to be de-allocated
  192.     //
  193.     //------------------------------------------------------------------------
  194.     STDMETHOD(DestroyMeshContainer)(THIS_ LPD3DXMESHCONTAINER pMeshContainerToFree) PURE; 
  195. };
  196.  
  197. //----------------------------------------------------------------------------
  198. // This interface is implemented by the application to load user data in a .X file
  199. //   When user data is found, these callbacks will be used to allow the application
  200. //   to load the data
  201. //----------------------------------------------------------------------------
  202. //////////////////////////////////////////////////////////////////////////////
  203. // ID3DXLoadUserData ////////////////////////////////////////////////////////
  204. //////////////////////////////////////////////////////////////////////////////
  205. DECLARE_INTERFACE(ID3DXLoadUserData)
  206. {
  207.     STDMETHOD(LoadTopLevelData)(LPDIRECTXFILEDATA pXofChildData) PURE;
  208.                             
  209.     STDMETHOD(LoadFrameChildData)(LPD3DXFRAME pFrame, 
  210.                             LPDIRECTXFILEDATA pXofChildData) PURE;
  211.                             
  212.     STDMETHOD(LoadMeshChildData)(LPD3DXMESHCONTAINER pMeshContainer, 
  213.                             LPDIRECTXFILEDATA pXofChildData) PURE;                            
  214. };
  215.  
  216. //----------------------------------------------------------------------------
  217. // This interface is implemented by the application to save user data in a .X file
  218. //   The callbacks are called for all data saved.  The user can then add any
  219. //   child data objects to the object provided to the callback
  220. //----------------------------------------------------------------------------
  221. //////////////////////////////////////////////////////////////////////////////
  222. // ID3DXSaveUserData /////////////////////////////////////////////////////////
  223. //////////////////////////////////////////////////////////////////////////////
  224. DECLARE_INTERFACE(ID3DXSaveUserData)
  225. {
  226.     STDMETHOD(AddFrameChildData)(LPD3DXFRAME pFrame, 
  227.                             LPDIRECTXFILESAVEOBJECT pXofSave, 
  228.                             LPDIRECTXFILEDATA pXofFrameData) PURE;
  229.                             
  230.     STDMETHOD(AddMeshChildData)(LPD3DXMESHCONTAINER pMeshContainer, 
  231.                             LPDIRECTXFILESAVEOBJECT pXofSave, 
  232.                             LPDIRECTXFILEDATA pXofMeshData) PURE;
  233.                             
  234.     // NOTE: this is called once per Save.  All top level objects should be added using the 
  235.     //    provided interface.  One call adds objects before the frame hierarchy, the other after
  236.     STDMETHOD(AddTopLevelDataObjectsPre)(LPDIRECTXFILESAVEOBJECT pXofSave) PURE; 
  237.     STDMETHOD(AddTopLevelDataObjectsPost)(LPDIRECTXFILESAVEOBJECT pXofSave) PURE;                             
  238.  
  239.     // callbacks for the user to register and then save templates to the XFile
  240.     STDMETHOD(RegisterTemplates)(LPDIRECTXFILE pXFileApi) PURE;                             
  241.     STDMETHOD(SaveTemplates)(LPDIRECTXFILESAVEOBJECT pXofSave) PURE;                             
  242. };
  243.  
  244. #ifdef __cplusplus
  245. extern "C" {
  246. #endif //__cplusplus
  247.  
  248.  
  249. //----------------------------------------------------------------------------
  250. // D3DXLoadMeshHierarchyFromX:
  251. // ---------------------------
  252. // Loads the first frame hierarchy in a .X file.
  253. //
  254. // Parameters:
  255. //  Filename
  256. //      Name of the .X file
  257. //  MeshOptions
  258. //      Mesh creation options for meshes in the file (see d3dx9mesh.h)
  259. //  pD3DDevice
  260. //      D3D9 device on which meshes in the file are created in
  261. //  pAlloc
  262. //      Allocation interface used to allocate nodes of the frame hierarchy
  263. //  pUserDataLoader
  264. //      Application provided interface to allow loading of user data
  265. //  ppFrameHierarchy
  266. //      Returns root node pointer of the loaded frame hierarchy
  267. //  ppAnimController
  268. //      Returns pointer to an animation controller corresponding to animation
  269. //        in the .X file. This is created with default max tracks and events
  270. //
  271. //----------------------------------------------------------------------------
  272. HRESULT WINAPI 
  273.     D3DXLoadMeshHierarchyFromXA(
  274.         LPCSTR Filename,
  275.         DWORD MeshOptions,
  276.         LPDIRECT3DDEVICE9 pD3DDevice,
  277.         LPD3DXALLOCATEHIERARCHY pAlloc,
  278.         LPD3DXLOADUSERDATA pUserDataLoader, 
  279.         LPD3DXFRAME *ppFrameHierarchy,
  280.         LPD3DXANIMATIONCONTROLLER *ppAnimController
  281. );
  282.  
  283. HRESULT WINAPI 
  284.     D3DXLoadMeshHierarchyFromXW(
  285.         LPCWSTR Filename,
  286.         DWORD MeshOptions,
  287.         LPDIRECT3DDEVICE9 pD3DDevice,
  288.         LPD3DXALLOCATEHIERARCHY pAlloc,
  289.         LPD3DXLOADUSERDATA pUserDataLoader, 
  290.         LPD3DXFRAME *ppFrameHierarchy,
  291.         LPD3DXANIMATIONCONTROLLER *ppAnimController
  292. );
  293.  
  294. #ifdef UNICODE
  295. #define D3DXLoadMeshHierarchyFromX D3DXLoadMeshHierarchyFromXW
  296. #else
  297. #define D3DXLoadMeshHierarchyFromX D3DXLoadMeshHierarchyFromXA
  298. #endif
  299.  
  300. HRESULT WINAPI 
  301.     D3DXLoadMeshHierarchyFromXInMemory(
  302.         LPCVOID Memory,
  303.         DWORD SizeOfMemory,
  304.         DWORD MeshOptions,
  305.         LPDIRECT3DDEVICE9 pD3DDevice,
  306.         LPD3DXALLOCATEHIERARCHY pAlloc,
  307.         LPD3DXLOADUSERDATA pUserDataLoader, 
  308.         LPD3DXFRAME *ppFrameHierarchy,
  309.         LPD3DXANIMATIONCONTROLLER *ppAnimController
  310. );
  311.  
  312. //----------------------------------------------------------------------------
  313. // D3DXSaveMeshHierarchyToFile:
  314. // ---------------------------
  315. // Creates a .X file and saves the mesh hierarchy and corresponding animations
  316. // in it
  317. //
  318. // Parameters:
  319. //  Filename
  320. //      Name of the .X file
  321. //  XFormat
  322. //      Format of the .X file (text or binary, compressed or not, etc)
  323. //  pFrameRoot
  324. //      Root node of the hierarchy to be saved
  325. //  pAnimController
  326. //      The animation mixer whose animation sets are to be stored
  327. //  pUserDataSaver
  328. //      Application provided interface to allow adding of user data to
  329. //        data objects saved to .X file
  330. //
  331. //----------------------------------------------------------------------------
  332. HRESULT WINAPI 
  333.     D3DXSaveMeshHierarchyToFileA(
  334.         LPCSTR Filename,
  335.         DWORD XFormat,
  336.         LPD3DXFRAME pFrameRoot, 
  337.         LPD3DXANIMATIONCONTROLLER pAnimMixer,
  338.         LPD3DXSAVEUSERDATA pUserDataSaver
  339. );
  340.  
  341. HRESULT WINAPI 
  342.     D3DXSaveMeshHierarchyToFileW(
  343.         LPCWSTR Filename,
  344.         DWORD XFormat,
  345.         LPD3DXFRAME pFrameRoot, 
  346.         LPD3DXANIMATIONCONTROLLER pAnimMixer,
  347.         LPD3DXSAVEUSERDATA pUserDataSaver
  348. );
  349.  
  350. #ifdef UNICODE
  351. #define D3DXSaveMeshHierarchyToFile D3DXSaveMeshHierarchyToFileW
  352. #else
  353. #define D3DXSaveMeshHierarchyToFile D3DXSaveMeshHierarchyToFileA
  354. #endif
  355.  
  356. //----------------------------------------------------------------------------
  357. // D3DXFrameDestroy:
  358. // -----------------
  359. // Destroys the subtree of frames under the root, including the root
  360. //
  361. // Parameters:
  362. //    pFrameRoot
  363. //        Pointer to the root node
  364. //  pAlloc
  365. //      Allocation interface used to de-allocate nodes of the frame hierarchy
  366. //
  367. //----------------------------------------------------------------------------
  368. HRESULT WINAPI
  369.     D3DXFrameDestroy(
  370.         LPD3DXFRAME pFrameRoot,
  371.         LPD3DXALLOCATEHIERARCHY pAlloc
  372. );
  373.  
  374. //----------------------------------------------------------------------------
  375. // D3DXFrameAppendChild:
  376. // ---------------------
  377. // Add a child frame to a frame
  378. //
  379. // Parameters:
  380. //    pFrameParent
  381. //        Pointer to the parent node
  382. //  pFrameChild
  383. //      Pointer to the child node
  384. //
  385. //----------------------------------------------------------------------------
  386. HRESULT WINAPI 
  387.     D3DXFrameAppendChild(
  388.         LPD3DXFRAME pFrameParent,
  389.         LPD3DXFRAME pFrameChild
  390. );
  391.  
  392. //----------------------------------------------------------------------------
  393. // D3DXFrameFind:
  394. // --------------
  395. // Finds a frame with the given name.  Returns NULL if no frame found.
  396. //
  397. // Parameters:
  398. //    pFrameRoot
  399. //        Pointer to the root node
  400. //  Name
  401. //      Name of frame to find
  402. //
  403. //----------------------------------------------------------------------------
  404. LPD3DXFRAME WINAPI 
  405.     D3DXFrameFind(
  406.         LPD3DXFRAME pFrameRoot,
  407.         LPCSTR Name
  408. );
  409.  
  410. //----------------------------------------------------------------------------
  411. // D3DXFrameRegisterNamedMatrices:
  412. // --------------------------
  413. // Finds all frames that have non-null names and registers each of those frame
  414. // matrices to the given animation mixer
  415. //
  416. // Parameters:
  417. //    pFrameRoot
  418. //        Pointer to the root node
  419. //    pAnimMixer
  420. //        Pointer to the animation mixer where the matrices are registered
  421. //
  422. //----------------------------------------------------------------------------
  423. HRESULT WINAPI
  424.     D3DXFrameRegisterNamedMatrices(
  425.         LPD3DXFRAME pFrameRoot,
  426.         LPD3DXANIMATIONCONTROLLER pAnimMixer
  427. );
  428.  
  429. //----------------------------------------------------------------------------
  430. // D3DXFrameNumNamedMatrices:
  431. // --------------------------
  432. // Counts number of frames in a subtree that have non-null names 
  433. //
  434. // Parameters:
  435. //    pFrameRoot
  436. //        Pointer to the root node of the subtree
  437. // Return Value:
  438. //        Count of frames
  439. //
  440. //----------------------------------------------------------------------------
  441. UINT WINAPI
  442.     D3DXFrameNumNamedMatrices(
  443.         LPD3DXFRAME pFrameRoot
  444. );
  445.  
  446. //----------------------------------------------------------------------------
  447. // D3DXFrameCalculateBoundingSphere:
  448. // ---------------------------------
  449. // Computes the bounding sphere of all the meshes in the frame hierarchy
  450. //
  451. // Parameters:
  452. //    pFrameRoot
  453. //        Pointer to the root node
  454. //    pObjectCenter
  455. //        Returns the center of the bounding sphere
  456. //    pObjectRadius
  457. //        Returns the radius of the bounding sphere
  458. //
  459. //----------------------------------------------------------------------------
  460. HRESULT WINAPI
  461.     D3DXFrameCalculateBoundingSphere(
  462.         LPD3DXFRAME pFrameRoot, 
  463.         LPD3DXVECTOR3 pObjectCenter, 
  464.         FLOAT *pObjectRadius
  465. );
  466.  
  467. #ifdef __cplusplus
  468. }
  469. #endif //__cplusplus
  470.  
  471. #undef INTERFACE
  472. #define INTERFACE ID3DXInterpolator
  473.  
  474. //----------------------------------------------------------------------------
  475. // This interface defines a SRT (scale/rotate/translate) interpolator. This
  476. // is an abstract interface. ID3DXKeyFrameInterpolator inherits from this.
  477. // An application can implement this for custom SRT interpolator
  478. //----------------------------------------------------------------------------
  479. //////////////////////////////////////////////////////////////////////////////
  480. // ID3DXInterpolator /////////////////////////////////////////////////////////
  481. //////////////////////////////////////////////////////////////////////////////
  482. DECLARE_INTERFACE_(ID3DXInterpolator, IUnknown)
  483. {
  484.     // IUnknown
  485.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  486.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  487.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  488.  
  489.     // ID3DXInterpolator
  490.     STDMETHOD_(LPCSTR, GetName)(THIS) PURE;
  491.     STDMETHOD_(DOUBLE, GetPeriod)(THIS) PURE;
  492.  
  493.     //----------------------------------------------------------------------------
  494.     // GetSRT:
  495.     // -------
  496.     // Returns the scale, rotation and translation at a given time
  497.     //
  498.     // Parameters:
  499.     //    Time
  500.     //        Time at which the interpolator should be queried
  501.     //    pScale
  502.     //        Returns the scale vector
  503.     //    pRotate
  504.     //        Returns the rotation qaternion
  505.     //    pTranslate
  506.     //        Returns the translate vector
  507.     //
  508.     //----------------------------------------------------------------------------
  509.     STDMETHOD(GetSRT)(THIS_ DOUBLE Time, D3DXVECTOR3 *pScale, D3DXQUATERNION *pRotate, D3DXVECTOR3 *pTranslate) PURE;
  510.     STDMETHOD(GetLastSRT)(THIS_ D3DXVECTOR3 *pScale, D3DXQUATERNION *pRotate, D3DXVECTOR3 *pTranslate) PURE;
  511. };
  512.  
  513.  
  514.  
  515.  
  516. //----------------------------------------------------------------------------
  517. // This structure describes a vector key for use in keyframe animation.
  518. // It specifies a vector Value at a given Time. This is used for scale and
  519. // translation keys
  520. //----------------------------------------------------------------------------
  521. typedef struct _D3DXKEY_VECTOR3
  522. {
  523.     FLOAT Time;
  524.     D3DXVECTOR3 Value;
  525. } D3DXKEY_VECTOR3, *LPD3DXKEY_VECTOR3;
  526.  
  527.  
  528. //----------------------------------------------------------------------------
  529. // This structure describes a quaternion key for use in keyframe animation.
  530. // It specifies a quaternion Value at a given Time. This is used for rotation
  531. // keys
  532. //----------------------------------------------------------------------------
  533. typedef struct _D3DXKEY_QUATERNION
  534. {
  535.     FLOAT Time;
  536.     D3DXQUATERNION Value;
  537. } D3DXKEY_QUATERNION, *LPD3DXKEY_QUATERNION;
  538.  
  539.  
  540. #undef INTERFACE
  541. #define INTERFACE ID3DXKeyFrameInterpolator
  542.  
  543. //----------------------------------------------------------------------------
  544. // This interface implements an SRT (scale/rotate/translate) interpolator
  545. // It takes a scattered set of keys and interpolates the transform for any
  546. // given time
  547. //----------------------------------------------------------------------------
  548. //////////////////////////////////////////////////////////////////////////////
  549. // ID3DXKeyFrameInterpolator /////////////////////////////////////////////////
  550. //////////////////////////////////////////////////////////////////////////////
  551. DECLARE_INTERFACE_(ID3DXKeyFrameInterpolator, ID3DXInterpolator)
  552. {
  553.     // IUnknown
  554.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  555.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  556.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  557.  
  558.     // ID3DXInterpolator
  559.     STDMETHOD_(LPCSTR, GetName)(THIS) PURE;
  560.     STDMETHOD_(DOUBLE, GetPeriod)(THIS) PURE;
  561.  
  562.     STDMETHOD(GetSRT)(THIS_ DOUBLE Time, D3DXVECTOR3 *pScale, D3DXQUATERNION *pRotate, D3DXVECTOR3 *pTranslate) PURE;
  563.     STDMETHOD(GetLastSRT)(THIS_ D3DXVECTOR3 *pScale, D3DXQUATERNION *pRotate, D3DXVECTOR3 *pTranslate) PURE;
  564.  
  565.     // ID3DXKeyFrameInterpolator
  566.     STDMETHOD_(UINT, GetNumScaleKeys)(THIS) PURE;
  567.     STDMETHOD(GetScaleKeys)(THIS_ LPD3DXKEY_VECTOR3 pKeys) PURE;
  568.  
  569.     STDMETHOD_(UINT, GetNumRotationKeys)(THIS) PURE;
  570.     STDMETHOD(GetRotationKeys)(THIS_ LPD3DXKEY_QUATERNION pKeys) PURE;
  571.  
  572.     STDMETHOD_(UINT, GetNumTranslationKeys)(THIS) PURE;
  573.     STDMETHOD(GetTranslationKeys)(THIS_ LPD3DXKEY_VECTOR3 pKeys) PURE;
  574.  
  575.     // the value passed to D3DXCreateKeyFrameInterpolator to scale from the times in LPD3DXKEY_VECTOR3 to global/anim time.
  576.     STDMETHOD_(DOUBLE, GetSourceTicksPerSecond)(THIS) PURE;
  577. };
  578.  
  579.  
  580.  
  581. //----------------------------------------------------------------------------
  582. // This interface implements an set of interpolators. The set consists of
  583. // interpolators for many nodes for the same animation. 
  584. //----------------------------------------------------------------------------
  585. //////////////////////////////////////////////////////////////////////////////
  586. // ID3DXAnimationSet /////////////////////////////////////////////////////////
  587. //////////////////////////////////////////////////////////////////////////////
  588. DECLARE_INTERFACE_(ID3DXAnimationSet, IUnknown)
  589. {
  590.     // IUnknown
  591.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  592.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  593.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  594.  
  595.     // ID3DXAnimationSet
  596.     STDMETHOD_(LPCSTR, GetName)(THIS) PURE;
  597.     STDMETHOD_(DOUBLE, GetPeriod)(THIS) PURE;
  598.  
  599.     STDMETHOD_(UINT, GetNumInterpolators)(THIS) PURE;
  600.     STDMETHOD(GetInterpolatorByIndex)(THIS_ UINT Index, LPD3DXINTERPOLATOR *ppInterpolator) PURE;
  601.     STDMETHOD(GetInterpolatorByName)(THIS_ LPCSTR pName, LPD3DXINTERPOLATOR *ppInterpolator) PURE;
  602. };
  603.  
  604. //----------------------------------------------------------------------------
  605. // This structure describes an animation track. A track is a combination
  606. //  of an animation set (stored separately) and mixing information.
  607. //  the mixing information consists of the current position, speed, and blending
  608. //  weight for the track.  The Flags field also specifies whether the track
  609. //  is low or high priority.  Tracks with the same priority are blended together
  610. //  and then the two resulting values are blended using the priority blend factor.
  611. //----------------------------------------------------------------------------
  612. typedef struct _D3DXTRACK_DESC
  613. {
  614.     DWORD Flags;
  615.     FLOAT Weight;
  616.     FLOAT Speed;
  617.     BOOL  Enable;
  618.     DOUBLE AnimTime;
  619. } D3DXTRACK_DESC, *LPD3DXTRACK_DESC;
  620.  
  621. //----------------------------------------------------------------------------
  622. // This enum defines the type of transtion performed on a event that transitions from one value to another
  623. //----------------------------------------------------------------------------
  624. typedef enum _D3DXTRACKFLAG {
  625.     D3DXTF_LOWPRIORITY            = 0x000,     // This track should be blended with all low priority tracks before mixed with the high priority result
  626.     D3DXTF_HIGHPRIORITY           = 0x001,     // This track should be blended with all high priority tracks before mixed with the low priority result
  627.  
  628.     D3DXTF_FORCE_DWORD    = 0x7fffffff, /* force 32-bit size enum */
  629. } D3DXTRACKFLAG;
  630.  
  631.  
  632. //----------------------------------------------------------------------------
  633. // This interface implements the main animation functionality. It connects
  634. // animation sets with the transform frames that are being animated. Allows
  635. // mixing multiple animations for blended animations or for transistions
  636. // It adds also has methods to modify blending parameters over time to 
  637. // enable smooth transistions and other effects.
  638. //----------------------------------------------------------------------------
  639.  
  640.  
  641. //----------------------------------------------------------------------------
  642. // This enum defines the type of transtion performed on a event that transitions from one value to another
  643. //----------------------------------------------------------------------------
  644. typedef enum _D3DXTRANSITIONTYPE {
  645.     D3DXTRANSITION_LINEAR            = 0x000,     // Linear transition from one value to the next
  646.     D3DXTRANSITION_EASEINEASEOUT     = 0x001,     // Ease-In Ease-Out spline transtion from one value to the next
  647.  
  648.     D3DXTRANSITION_FORCE_DWORD    = 0x7fffffff, /* force 32-bit size enum */
  649. } D3DXTRANSITIONTYPE;
  650.  
  651.  
  652. //////////////////////////////////////////////////////////////////////////////
  653. // ID3DXAnimationController //////////////////////////////////////////////////
  654. //////////////////////////////////////////////////////////////////////////////
  655. DECLARE_INTERFACE_(ID3DXAnimationController, IUnknown)
  656. {
  657.   // IUnknown
  658.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  659.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  660.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  661.  
  662.   // mixing functionality
  663.     // register outputs of SetTime
  664.     STDMETHOD(RegisterMatrix)(THIS_ LPCSTR Name, D3DXMATRIX *pMatrix) PURE;
  665.  
  666.  
  667.     // AnimationSets
  668.     STDMETHOD_(UINT, GetNumAnimationSets)(THIS) PURE;
  669.     STDMETHOD(GetAnimationSet)(THIS_ DWORD iAnimationSet, LPD3DXANIMATIONSET *ppAnimSet) PURE;
  670.  
  671.     STDMETHOD(RegisterAnimationSet)(THIS_ LPD3DXANIMATIONSET pAnimSet) PURE;
  672.     STDMETHOD(UnregisterAnimationSet)(THIS_ LPD3DXANIMATIONSET pAnimSet) PURE;
  673.  
  674.  
  675.     // Tracks
  676.     STDMETHOD_(UINT, GetMaxNumTracks)(THIS) PURE;
  677.     STDMETHOD(GetTrackDesc)(THIS_ DWORD Track, D3DXTRACK_DESC *pDesc) PURE;
  678.     STDMETHOD(SetTrackDesc)(THIS_ DWORD Track, D3DXTRACK_DESC *pDesc) PURE;
  679.     
  680.     STDMETHOD(GetTrackAnimationSet)(THIS_ DWORD Track, LPD3DXANIMATIONSET *ppAnimSet) PURE;
  681.     STDMETHOD(SetTrackAnimationSet)(THIS_ DWORD Track, LPD3DXANIMATIONSET pAnimSet) PURE;
  682.  
  683.     // Individual track field access
  684.     STDMETHOD(SetTrackSpeed)(THIS_ DWORD Track, FLOAT Speed) PURE;
  685.     STDMETHOD(SetTrackWeight)(THIS_ DWORD Track, FLOAT Weight) PURE;
  686.     STDMETHOD(SetTrackAnimTime)(THIS_ DWORD Track, DOUBLE AnimTime) PURE;
  687.     STDMETHOD(SetTrackEnable)(THIS_ DWORD Track, BOOL Enable) PURE;
  688.  
  689.     // Time
  690.     STDMETHOD_(DOUBLE, GetTime)(THIS) PURE;
  691.     STDMETHOD(SetTime)(THIS_ DOUBLE Time) PURE;
  692.  
  693.     STDMETHOD(CloneAnimationController)(THIS_ UINT MaxNumMatrices, UINT MaxNumAnimationSets, UINT MaxNumTracks, UINT MaxNumEvents, LPD3DXANIMATIONCONTROLLER *ppAnimController) PURE;
  694.  
  695.     STDMETHOD_(UINT, GetMaxNumMatrices)(THIS) PURE;
  696.     STDMETHOD_(UINT, GetMaxNumEvents)(THIS) PURE;
  697.     STDMETHOD_(UINT, GetMaxNumAnimationSets)(THIS) PURE;
  698.  
  699.   // Sequencing abilities
  700.     STDMETHOD(KeyTrackSpeed)(THIS_ DWORD Track, FLOAT NewSpeed, DOUBLE StartTime, DOUBLE Duration, DWORD Method) PURE;
  701.     STDMETHOD(KeyTrackWeight)(THIS_ DWORD Track, FLOAT NewWeight, DOUBLE StartTime, DOUBLE Duration, DWORD Method) PURE;
  702.     STDMETHOD(KeyTrackAnimTime)(THIS_ DWORD Track, DOUBLE NewAnimTime, DOUBLE StartTime) PURE;
  703.     STDMETHOD(KeyTrackEnable)(THIS_ DWORD Track, BOOL NewEnable, DOUBLE StartTime) PURE;
  704.  
  705.     // this functions sets the blend weight to be used to blend high and low priority tracks together.
  706.     //  NOTE: this has no effect unless there are active animations on tracks for a given matrix that have both high and low results
  707.     STDMETHOD_(FLOAT, GetPriorityBlend)(THIS) PURE;
  708.     STDMETHOD(SetPriorityBlend)(THIS_ FLOAT BlendWeight) PURE;
  709.  
  710.     STDMETHOD(KeyPriorityBlend)(THIS_ FLOAT NewBlendWeight, DOUBLE StartTime, DOUBLE Duration, DWORD Method) PURE;
  711. };
  712.  
  713. #ifdef __cplusplus
  714. extern "C" {
  715. #endif //__cplusplus
  716.  
  717. //----------------------------------------------------------------------------
  718. // D3DXCreateKeyFrameInterpolator:
  719. // -------------------------------
  720. // Creates a SRT key frame interpolator object from the given set of keys
  721. //
  722. // Parameters:
  723. //    ScaleKeys
  724. //        Array of scale key vectors
  725. //    NumScaleKeys
  726. //        Num elements in ScaleKeys array
  727. //    RotationKeys
  728. //        Array of rotation key quternions
  729. //    NumRotationKeys
  730. //        Num elements in RotationKeys array
  731. //    TranslateKeys
  732. //        Array of translation key vectors
  733. //    NumTranslateKeys
  734. //        Num elements in TranslateKeys array
  735. //    ScaleInputTimeBy
  736. //        All key times are scaled by this factor
  737. //    ppNewInterpolator
  738. //        Returns the keyframe interpolator interface
  739. //
  740. //----------------------------------------------------------------------------
  741. HRESULT WINAPI
  742. D3DXCreateKeyFrameInterpolator(LPCSTR Name, 
  743.                             LPD3DXKEY_VECTOR3    ScaleKeys,     UINT NumScaleKeys,
  744.                             LPD3DXKEY_QUATERNION RotationKeys,  UINT NumRotationKeys,
  745.                             LPD3DXKEY_VECTOR3    TranslateKeys, UINT NumTranslateKeys,
  746.                             DOUBLE ScaleInputTimeBy, LPD3DXKEYFRAMEINTERPOLATOR *ppNewInterpolator);
  747.  
  748. //----------------------------------------------------------------------------
  749. // D3DXCreateAnimationSet:
  750. // -----------------------
  751. // Creates an animtions set interface given a set of interpolators
  752. //
  753. // Parameters:
  754. //    Name
  755. //        Name of the animation set
  756. //    pInterpolators
  757. //        Array of interpolators
  758. //    NumInterpolators
  759. //        Num elements in the pInterpolators array
  760. //    ppAnimSet
  761. //        Returns the animation set interface
  762. //
  763. //-----------------------------------------------------------------------------        
  764. HRESULT WINAPI
  765. D3DXCreateAnimationSet(LPCSTR Name, 
  766.                             LPD3DXINTERPOLATOR *ppInterpolators, UINT NumInterpolators,
  767.                             LPD3DXANIMATIONSET *ppAnimSet);
  768.  
  769. //----------------------------------------------------------------------------
  770. // D3DXCreateAnimationController:
  771. // -------------------------
  772. // Creates an animtion mixer object
  773. //
  774. // Parameters:
  775. //    MaxNumMatrices
  776. //        The upper limit for the number of matrices that can be animated by the
  777. //        the object
  778. //    MaxNumAnimationSets
  779. //        The upper limit of the number of animation sets that can be played by
  780. //        the object
  781. //    MaxNumTracks
  782. //        The upper limit of the number of animation sets that can be blended at
  783. //        any time.
  784. //    MaxNumEvents
  785. //        The upper limit of the number of outstanding events that can be
  786. //        scheduled at once.
  787. //    ppAnimController
  788. //        Returns the animation controller interface
  789. //
  790. //-----------------------------------------------------------------------------        
  791. HRESULT WINAPI
  792. D3DXCreateAnimationController(UINT MaxNumMatrices, UINT MaxNumAnimationSets, UINT MaxNumTracks, UINT MaxNumEvents,
  793.                                  LPD3DXANIMATIONCONTROLLER *ppAnimController);
  794.  
  795. #ifdef __cplusplus
  796. }
  797. #endif //__cplusplus
  798.  
  799. #endif //__D3DX9ANIM_H__
  800.  
  801.  
  802.